﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for EditBasePage
/// </summary>
public class EditBasePage : System.Web.UI.Page
{
	public EditBasePage()
	{
	}

    protected ListView listViewHolder;
    protected string ViewStateConst;
    protected ObjectDataSource objectServiceHolder;
    protected Button confirmButtonHolder;
    protected string targetMailAddress;

    public delegate void DoStuff(string s1, string s2);

    protected void SendOut(string s1, string s2)
    {
        SendMail.Send(targetMailAddress, "Update:" + s1,
           s2, false, ConstStrings.RootMail);
    }

    protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        foreach (ListViewDataItem item in this.listViewHolder.Items)
        {
            this.listViewHolder.UpdateItem(item.DataItemIndex, false);
        }
    }

    protected void ListView1_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        // The ListIndex parameter could have been defined in the aspx - DeleteParameters collection of the ObjectDataSource,
        //  but then we'd have to reference it here by objOfficer.DeleteParameters["ListIndex"].DefaultValue - and unfortunately
        //   DefaultValue only accepts strings (regardless of Parameter type)
        objectServiceHolder.DeleteParameters.Clear();
        objectServiceHolder.DeleteParameters.Add(new Parameter("ListIndex", TypeCode.Int16, e.ItemIndex.ToString()));
    }

    protected override void OnLoad(EventArgs e)
    {

        base.OnLoad(e);

        if (!this.IsPostBack)
        {
            this.confirmButtonHolder.Enabled = false;
        }
        else
        {
            this.confirmButtonHolder.Enabled = true;
        }

        if (User.Identity.IsAuthenticated)
        {
            global::User user = UserManager.GetInstance().FindUser(User.Identity.Name);
            {
                if(user.IsValidate)
                {
                    this.listViewHolder.Visible = true;
                    return;
                }
            }
        }
        this.listViewHolder.Visible = false;
    }
}